package com.kunpan.admin.common.redis;

import com.alibaba.fastjson2.JSON;
import com.kunpan.admin.constant.RedisMessage;
import com.kunpan.admin.entity.dto.MessageDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


/**
 * 消息发布者
 */
@Component
public class RedisMessagePublisher {

    private static final Logger logger = LoggerFactory.getLogger(RedisMessagePublisher.class);

    @Autowired
    private RedisCache redisCache;

    /**
     * 发送文件上传完成通知
     *
     * @param messageDto 需要传递的消息对象
     */
    public void publishFileUploadEvent(MessageDto messageDto) {
        //发布主题消息
        redisCache.convertAndSend(RedisMessage.FILE_UPLOAD_SUCCESS, messageDto);
        logger.info("已发布缓存清理事件: {}", messageDto);
    }
}
